package com.teach.controller;

import com.teach.entity.ResponseEntity;
import com.teach.entity.TbRole;
import com.teach.service.TbRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/role")
@Api(tags = "角色表的控制层")
public class RoleController {
    @Resource
    private TbRoleService tbRoleService;

    /**
     * 角色列表
     * @param tbRole
     * @return
     */
    @PostMapping("/list")
    @ApiOperation("角色列表")
    public ResponseEntity list(@RequestBody TbRole tbRole){
        return tbRoleService.getAll(tbRole);
    }

    /**
     * 角色表添加
     * @param tbRole
     * @param request
     * @return
     */
    @ApiOperation("角色添加")
    @PostMapping("/roleSave")
    public ResponseEntity roleSave(@RequestBody TbRole tbRole, HttpServletRequest request){
        String token = request.getHeader("token");
        return tbRoleService.roleSave(tbRole,token);
    }

    /**
     * 角色修改
     * @param tbRole
     * @return
     */
    @PostMapping("/updateRole")
    @ApiOperation("角色的修改")
    public ResponseEntity updateRole(@RequestBody TbRole tbRole,HttpServletRequest request){
        String token = request.getHeader("token");
        return tbRoleService.updateRole(tbRole,token);
    }

}
